import request from '@/utils/request'

// 查询收藏列表
export function listFavorite(query) {
  return request({
    url: '/bookbus/favorite/list',
    method: 'get',
    params: query
  })
}

// 查询收藏详细
export function getFavorite(id) {
  return request({
    url: '/bookbus/favorite/' + id,
    method: 'get'
  })
}

// 新增收藏
export function addFavorite(data) {
  return request({
    url: '/bookbus/favorite',
    method: 'post',
    data: data
  })
}

// 修改收藏
export function updateFavorite(data) {
  return request({
    url: '/bookbus/favorite',
    method: 'put',
    data: data
  })
}

// 删除收藏
export function delFavorite(id) {
  // 如果是数组，转换为逗号分隔的字符串
  const ids = Array.isArray(id) ? id.join(',') : id
  return request({
    url: '/bookbus/favorite/' + ids,
    method: 'delete'
  })
}

// 清空当前用户的所有收藏（客户端接口）
export function deleteAllByMy() {
  return request({
    url: '/favorite/deleteAllByMy',
    method: 'delete'
  })
}
